package com.zzyl.nursing.controller.member;

import com.zzyl.common.core.domain.R;
import com.zzyl.common.core.page.TableDataInfo;
import com.zzyl.nursing.domain.Reservation;
import com.zzyl.nursing.service.ReservationService;
import com.zzyl.nursing.vo.ReservationVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Api(tags = "用户端预约管理")
@RestController
@RequestMapping("/member/reservation")
public class ReservationController {

    @Autowired
    private ReservationService reservationService;

    @ApiOperation("新增预约")
    @PostMapping
    public R<String> insertReservation(@RequestBody Reservation reservation) {
        reservationService.insertReservation(reservation);
        return R.ok();
    }

    @ApiOperation("取消预约")
    @PutMapping("/{id}/cancel")
    public R<String> cancelReservation(@PathVariable Long id) {
        reservationService.cancelReservation(id);
        return R.ok();
    }

    @ApiOperation("查询取消预约数量")
    @GetMapping("/cancelled-count")
    public R<Integer> selectCancelledCount() {
        Integer count = reservationService.getCancelledCount();
        return R.ok(count);
    }

    @ApiOperation("分页查询预约")
    @GetMapping("/page")
    public R<TableDataInfo<Reservation>> selectReservationByPage(Integer status, Integer pageNum, Integer pageSize) {
        TableDataInfo<Reservation> tableDataInfo = reservationService.selectReservationByPage(status, pageNum, pageSize);
        return R.ok(tableDataInfo);
    }

    @ApiOperation("查询每个时间段剩余的预约此数")
    @GetMapping("/countByTime")
    public R<List<ReservationVo>> selectCountByTime(Long time) {
        List<ReservationVo> reservationVos = reservationService.selectCountByTime(time);
        return R.ok(reservationVos);
    }
}
